package com.main.easycare;

import historique.HistoriqueActivity;
import nfc.LectureActivity;
import server.RequetesActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import ecriture.FormulaireEcriture;

public class MenuActivity extends Activity implements OnClickListener {

	private Button bouton_server;
	private Button bouton_historique;
	private Button bouton_lecture;
	private Button bouton_ecriture;
	private Button bouton_quitter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_menu);

		/*
		 * Initialisation des variables
		 */
		bouton_server = (Button)findViewById(R.id.menu_bouton_http);
		bouton_historique = (Button)findViewById(R.id.menu_bouton_historique);
		bouton_lecture = (Button)findViewById(R.id.menu_bouton_lecteur);
		bouton_ecriture = (Button)findViewById(R.id.menu_bouton_ecriture);
		bouton_quitter = (Button)findViewById(R.id.menu_bouton_quitter);

		/*
		 * On active la detection des clic de chaque bouton
		 */

		bouton_server.setOnClickListener(this);
		bouton_historique.setOnClickListener(this);
		bouton_lecture.setOnClickListener(this);
		bouton_ecriture.setOnClickListener(this);
		bouton_quitter.setOnClickListener(this);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public void onClick(View arg0) {
		if(arg0 == bouton_server){
			Intent intent = new Intent(MenuActivity.this, RequetesActivity.class);
			startActivityForResult(intent,0);
		}
		if(arg0 == bouton_ecriture){
			Intent intent = new Intent(MenuActivity.this, FormulaireEcriture.class);
			startActivityForResult(intent,0);
		}

		if(arg0 == bouton_historique){
			Intent intent = new Intent(MenuActivity.this, HistoriqueActivity.class);
			startActivityForResult(intent,0);
		}

		if(arg0 == bouton_lecture){
			Intent intent = new Intent(MenuActivity.this, LectureActivity.class);
			startActivityForResult(intent,0);
		}

		if(arg0 == bouton_quitter){

			AlertDialog.Builder boite;
			boite = new AlertDialog.Builder(MenuActivity.this);
			boite.setTitle("Quitter");
			boite.setIcon(R.drawable.ic_launcher);
			boite.setPositiveButton("Oui", new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog, int which) {
					System.exit(0);
				}
			}
					);

			boite.setNegativeButton("Non", new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog, int which) {

				}
			}
					);
			boite.show();
		}

	}

}
